package servlet.comm;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import factory.comm.UserDAOFactory;
import vo.comm.User;;
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public LoginServlet() {
        super();
    }
	public void init(ServletConfig config) throws ServletException {
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userid=request.getParameter("userid");
		String password=request.getParameter("password");
		User user=new User();
		user.setUserid(userid);
		user.setPassword(password);
		try {
			if(UserDAOFactory.getIUserDAOInstance().findLogin(user)){
				request.getSession().setAttribute("userid", user.getUserid());
				request.getSession().setAttribute("username", user.getName());
				request.getSession().setAttribute("authority", user.getAuthority());
				response.sendRedirect("user/login_success.jsp");
				System.out.println("OK");
			}
			else{
				response.sendRedirect("user/login_failure.jsp");
				System.out.println("NO");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
